// import XLSX from "xlsx";//隐藏通过首页引入
export const csvExport = (name = "表格导出", title = [], array = []) => {
  const output = [...title, ...array];
  let csvContent =
    "data:text/csv;charset=utf-8,\ufeff" +
    output.map(e => e.join(",\t")).join("\n");
  var link = document.createElement("a");
  link.setAttribute("href", encodeURI(csvContent));
  link.setAttribute("download", `${name}.csv`);
  document.body.appendChild(link); // Required for FF
  console.log("link", link);
  link.click();
  link.remove();
};

// 导出真实表格不是伪html
export const xlsxExport = (
  name = "表格导出",
  title = [],
  array = [],
  Sheet = "Sheet1"
) => {
  const ws = XLSX.utils.aoa_to_sheet([title, ...array]);
  const wb = XLSX.utils.book_new();
  const cols = [];
  const rows = [];

  array.forEach(e => {
    cols.push({
      wch: 20
    });
    rows.push({
      hpx: 22
    });
  });
  ws["!cols"] = cols;
  ws["!rows"] = rows;
  XLSX.utils.book_append_sheet(wb, ws, Sheet);
  XLSX.writeFile(wb, `${name}`);
};
